#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int rollDice( void )
{
	int die1, die2, workSum;
		die1 = 1 + ( rand() % 6 );
		die2 = 1 + ( rand() % 6 );
		workSum = die1 + die2;
		printf( "Player rolled %d + %d = %d\n", die1, die2, workSum );
return workSum;
}
bool craps()
{
	

		int gameStatus, sum, myPoint;
		srand( time( NULL ) );
		sum = rollDice( ); /* first roll of the dice */
		
		switch( sum ) {
		
		case 7: case 11: /* win on first roll */
		
			gameStatus = 1;
		
			break;
		
		case 2: case 3: case 12: /* lose on first roll */
		
			gameStatus = 2;
		
			break;
		
		default: /* remember point */
			gameStatus = 0;
			myPoint = sum;
			printf( "Point is %d\n", myPoint );
		
			break;
		}
		
		while ( gameStatus == 0 ) { /* keep rolling */
			sum = rollDice( );
		
			if ( sum == myPoint ) /* win by making point */
			
				gameStatus = 1;
		
			else
		
				if ( sum == 7 ) /* lose by rolling 7 */
			
					gameStatus = 2;
			
		}
		
		if ( gameStatus == 1 )
		{
			printf( "Player wins\n" );
			printf( "------------------------\n");
			return 1;
		}

		
		else{
			printf( "Player loses\n" );
			printf( "------------------------\n");
			return 0;
		}
		
		


}



int main()
{
	int k=1000, b;
	int a;
	
		printf("Your current balance is : 1000\n\n");

	while(k!=0){
		
		printf("Please enter a wager:");
		scanf("%d", &b);
		
		if(k>=b && b>0){
			a=craps();

			if(a==1){
				k=k+b;
				printf("%d\n", k);
			}
			if(a==0){
				k=k-b;
				printf("%d\n", k);		
			}
		}

	}

	printf("Sorry. You busted!.\n");

	return 0;
}
